(() => {
  let ele = {};
  ele.modal_tips = $("#modal-tips");
  ele.close_tips = $("#close-tips");
  ele.record = $("#record");
  ele.modal_record = $("#modal-record");
  ele.close_record = $("#close-record");
  ele.modal_explian = $("#modal-explian");
  ele.explian = $("#explian");
  ele.close_explian = $("#close-explian");
  ele.list_new = $("#list-new");
  ele.list_room = $("#list-room");
  ele.list_week = $("#list-week");
  ele.list_promote = $("#list-promote");
  ele.options = $("#tab-team li");
  ele.content = $(".content");
  ele.li = $("#tab-one li");
  ele.num_jin = $("#num_jin");
  ele.qifuqian = $("#qifuqian");
  ele.rule = $("#rule");
  ele.invitebtn = $("#invitebtn");
  ele.zhaocaijinbao = $("#zhaocaijinbao");
  ele.activeTime = $("#activeTime");
  ele.yaoqing1 = $("#yaoqing1");
  ele.yaoqing1_jdt = $("#yaoqing1_jdt");
  ele.yaoqing11 = $("#yaoqing11");
  ele.yaoqing2 = $("#yaoqing2");
  ele.yaoqing2_jdt = $("#yaoqing2_jdt");
  ele.yaoqing22 = $("#yaoqing22");
  ele.yq_lingqu = $("#yq_lingqu");
  ele.gian1 = $("#gian1");
  ele.tg_remark1 = $("#tg_remark1");
  ele.tg_remark11 = $("#tg_remark11");
  ele.tg_remark111 = $("#tg_remark111");
  ele.tg_remark2 = $("#tg_remark2");
  ele.tg_remark22 = $("#tg_remark22");
  ele.tg_remark222 = $("#tg_remark222");
  ele.tg_remark3 = $("#tg_remark3");
  ele.tg_remark33 = $("#tg_remark33");
  ele.tg_remark333 = $("#tg_remark333");
  ele.wodemoney = $("#wodemoney");
  ele.wuwei = $("#wuwei");
  ele.weekList = $("#weekList");
  ele.more = $("#more");
  ele.empty = $("#empty");
  ele.more1 = $("#more1");
  ele.empty1 = $("#empty1");
  ele.more2 = $("#more2");
  ele.empty2 = $("#empty2");
  ele.navcont = $("#navcont");
  ele.shouyibtn = $("#shouyibtn");
  ele.modal_record2 = $("#modal-record2");
  ele.close_record2 = $("#close-record2");
  ele.navtit2 = $("#navtit2");
  ele.navcont2 = $("#navcont2");
  ele.iptvalue = $("#iptvalue");
  ele.search = $("#search");
  ele.is_direct = $("#is_direct");
  ele.yqxq1 = $("#yqxq1");
  ele.leiji = $("#leiji");

  let page = 1;

  let type = getUrlParam("id");
  let types = 1;
  let zhao = {};
  if (type == 2) {
    ele.content[0].classList.remove("content-show");
    ele.content[2].classList.add("content-show");
    ele.li[0].classList.remove("option-active");
    ele.li[2].classList.add("option-active");
  } else if (type == 3) {
    ele.content[0].classList.remove("content-show");
    ele.content[3].classList.add("content-show");
    ele.li[0].classList.remove("option-active");
    ele.li[3].classList.add("option-active");
  }

  //关闭 任务说明
  ele.close_tips.onclick = () => {
    closeMdl(ele.modal_tips);
  };

  //打开 领取记录
  ele.record.onclick = () => {
    openMdl(ele.modal_record);
  };
  //关闭 领取记录
  ele.close_record.onclick = () => {
    closeMdl(ele.modal_record);
  };
  //关闭 邀请详情
  ele.close_record2.onclick = () => {
    closeMdl(ele.modal_record2);
  };

  //打开 每周任务说明
  ele.explian.onclick = () => {
    openMdl(ele.modal_explian);
  };
  // 点击邀请好友
  ele.invitebtn.onclick = () => {
    location.href = "../page/inviteFriend.html";
  };
  //关闭 每周任务说明
  ele.close_explian.onclick = () => {
    closeMdl(ele.modal_explian);
  };
  // todo点击规则
  ele.rule.onclick = () => {
    location.href = "../page/rule.html";
  };
  // taskList(1);

  const typeList = ["", "new", "room", "week", "promote"];

  let typeName = "new";

  tabBar();
  taskList(typeList.indexOf(typeName));

  // 选项卡选项功能
  function tabBar() {
    for (let i = 0; i < ele.options.length; i++) {
      ele.options[i].addEventListener("click", (e) => {
        let cls = e.target.className;
        typeName = cls.split(" ")[0].split("-")[1];
        // console.log(typeName, typeList.indexOf(typeName));
        if (i == 0 || i == 1) {
          taskList(typeList.indexOf(typeName));
          types = typeList.indexOf(typeName);
        }
      });
    }
  }

  // 任务列表
  function taskList(type) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.TASK_LIST,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        type: type,
      },
      success: (res) => {
        if (res.code == 1) {
          if (res.data.detail) {
            detail = res.data.detail;
          }
          if (type == 1) {
            drawListNew(res.data.list);
          } else if (type == 2) {
            drawListRoom(res.data.list);
            zhao = res.data.h_no;
          }
          // else if (type == 3) {
          // 	drawListWeek(res.data);
          // }
          // openTips(res.msg);
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  // 新手任务
  function drawListNew(_data) {
    let html = "";
    for (let i = 0; i < _data.length; i++) {
      //  unit 奖励类型 1金币 2零钱 3祈福签 4提到钱包
      let j = i + 1;
      let is_jb =
        _data[i].unit == 1
          ? "http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi.png"
          : "../img/task/hhb.png";
      html +=
        '<div class="item1">' +
        '<div class="left1">' +
        `<img style="display:${
          _data[i].task_id == 1 ? "block" : "none"
        };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/1.png" alt="">
      <img style="display:${
        _data[i].task_id == 2 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/2.png" alt="">  
      <img style="display:${
        _data[i].task_id == 3 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/3.png" alt="">  
      <img style="display:${
        _data[i].task_id == 4 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/4.png" alt="">  
      <img style="display:${
        _data[i].task_id == 5 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/5.png" alt="">  
      <img style="display:${
        _data[i].task_id == 6 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/6.png" alt="">  
      <img style="display:${
        _data[i].task_id == 7 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/7.png" alt="">  
      <img style="display:${
        _data[i].task_id == 8 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/8.png" alt="">  
      <img style="display:${
        _data[i].task_id == 9 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/9.png" alt="">  
      <img style="display:${
        _data[i].task_id == 10 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/10.png" alt="">  
      <img style="display:${
        _data[i].task_id == 11 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/11.png" alt="">  
      ` +
        '<div class="leftIn1">' +
        '<p class="remark">' +
        _data[i].describe +
        "</p>" +
        '<p class="rate">当前进度</p>' +
        '<div class="progress">' +
        `<p id="jindu" data-left="${
          _data[i].record ? _data[i].record.num : "0"
        }" data-right="${_data[i].num}"></p>` +
        "<span>" +
        `${_data[i].record ? _data[i].record.num : "0"}` +
        "/" +
        _data[i].num +
        "</span>" +
        "</div>" +
        '<div class="reward">' +
        '<p class="jiangli">奖励</p>' +
        '<img class="jinbi" src="' +
        is_jb +
        '" alt="">' +
        '<span class="number">X' +
        _data[i].money +
        "</span>" +
        "</div>" +
        "</div>" +
        "</div>" +
        // `<button style="display:${
        //   _data[i].state != 10 ? "block" : "none"
        // };" data-id="${_data[i].id}" id="btn_ling" class="${
        //   _data[i].record && _data[i].record.num <= _data[i].num
        //     ? "button3"
        //     : ""
        // }">${
        //   _data[i].record && _data[i].record.num <= _data[i].num
        //     ? "前往"
        //     : "领取"
        // }</button>` +
        `<button style="display:${
          _data[i].record &&
          _data[i].record.state == 0 &&
          _data[i].record.num >= _data[i].num
            ? "block"
            : "none"
        };" id="btn_ling" data-id="${_data[i].id}" class="">领取</button>` +
        `<button style="display:${
          _data[i].record && _data[i].record.state == 10 ? "block" : "none"
        };" class="button4">已领取</button>` +
        `<button id="qinawang" data-id="${_data[i].id}" style="display:${
          !_data[i].record ? "block" : "none"
        };" class="button3">前往</button>` +
        `<button id="qinawang" data-id="${_data[i].task_id}" style="display:${
          _data[i].record && _data[i].record.num < _data[i].num
            ? "block"
            : "none"
        };" class="button3">前往</button>` +
        "</div>";
    }
    ele.list_new.innerHTML = html;
    // !渲染进度条
    let jinduAll = document.querySelectorAll("#jindu");
    jinduAll.forEach((item) => {
      // console.log(item.dataset.left,item.dataset.right);
      if (parseInt(item.dataset.left) >= parseInt(item.dataset.right)) {
        // console.log(1);
        item.style.width = "calc(100% - 4px)";
      } else {
        let wi = (item.dataset.left / item.dataset.right) * 100;
        item.style.width = wi + "%";
      }
    });
    // !绑定点击领取事件----------
    let btn_lingAll = document.querySelectorAll("#btn_ling");
    btn_lingAll.forEach((item) => {
      item.onclick = () => {
        lingqu(item.dataset.id);
      };
    });
    // !点击前往
    let qinawangAll = document.querySelectorAll("#qinawang");
    qinawangAll.forEach((item) => {
      item.onclick = () => {
        if (item.dataset.id == 1) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 2) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 3) {
          location.href = "../page/energy_Fang.html";
        } else if (item.dataset.id == 4) {
          location.href = "../page/directEmploy.html";
        } else if (item.dataset.id == 5) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 6) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 7) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 8) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 9) {
          location.href = "../page/search.html";
        } else if (item.dataset.id == 10) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 11) {
          location.href = "../page/mine3.html";
        }
      };
    });
  }

  // 房间任务
  function drawListRoom(_data) {
    let html = "";
    let state = "";
    let itemcls = "";
    let btncls = "";
    // let btntxt = '';
    // 渲染祈福签
    console.log(detail);
    ele.qifuqian.innerHTML = detail.has_num;
    for (let i = 0; i < _data.length; i++) {
      //  unit 奖励类型 1金币 2零钱 3祈福签 4提到钱包
      // record.state  0  前往 5 领取 10已完成吧
      itemcls = _data[i].state == 2 ? "item2" : "item1";
      // btncls =
      //   _data[i].state == 0
      //     ? '<button class="gohead">前往</button>'
      //     : _data[i].state == 1
      //     ? "<button>领取</button>"
      //     : '<img class="okimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/ywc.png" alt="">';
      if (!_data[i].record) {
        btncls = `<button data-id="${_data[i].task_id}"  id="qianwang_renwu" class="gohead">前往</button>`;
      } else if (_data[i].record && _data[i].record.num < _data[i].num) {
        btncls = `<button data-id="${_data[i].task_id}"  id="qianwang_renwu" class="gohead" >前往</button>`;
      } else if (_data[i].record && _data[i].record.state == 10) {
        // !已完成
        // btncls = '<img class="okimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/ywc.png" alt="">';
        btncls = `<button class="button4">已领取</button>`;
      } else if (
        _data[i].record &&
        _data[i].record.state == 0 &&
        _data[i].record.num >= _data[i].num
      ) {
        btncls = `<button data-id="${_data[i].id}" id='btn_ling_s' >领取</button>`;
      }
      // btntxt == _data[i].state == 0 ? '前往' : '领取';
      let j = i + 7;
      console.log(_data[i].state);
      html +=
        '<div class="' +
        itemcls +
        '">' +
        '<div class="left1">' +
        `<img style="display:${
          _data[i].task_id == 1 ? "block" : "none"
        };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/1.png" alt="">
      <img style="display:${
        _data[i].task_id == 2 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/2.png" alt="">  
      <img style="display:${
        _data[i].task_id == 3 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/3.png" alt="">  
      <img style="display:${
        _data[i].task_id == 4 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/4.png" alt="">  
      <img style="display:${
        _data[i].task_id == 5 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/5.png" alt="">  
      <img style="display:${
        _data[i].task_id == 6 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/6.png" alt="">  
      <img style="display:${
        _data[i].task_id == 7 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/7.png" alt="">  
      <img style="display:${
        _data[i].task_id == 8 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/8.png" alt="">  
      <img style="display:${
        _data[i].task_id == 9 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/9.png" alt="">  
      <img style="display:${
        _data[i].task_id == 10 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/10.png" alt="">  
      <img style="display:${
        _data[i].task_id == 11 ? "block" : "none"
      };" class="typeimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/11.png" alt="">  
      ` +
        '<div class="leftIn1">' +
        '<p class="remark">' +
        _data[i].describe +
        "</p>" +
        '<p class="rate">当前进度</p>' +
        '<div class="progress">' +
        `<p id="jindu" data-left="${
          _data[i].record ? _data[i].record.num : "0"
        }" data-right="${_data[i].num}"></p>` +
        "<span>" +
        `${_data[i].record ? _data[i].record.num : "0"}` +
        "/" +
        _data[i].num +
        "</span>" +
        "</div>" +
        // +'<p class="complete">已完成</p>' +
        '<div class="reward">' +
        '<p class="jiangli">奖励</p>' +
        '<img class="jinbi" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/fu.png" alt="">' +
        '<span class="number">X' +
        _data[i].money +
        "</span>" +
        "</div>" +
        "</div>" +
        "</div>" +
        btncls +
        // +'<button>领取</button>'
        // +'<button class="'+btncls+'">'+btntxt+'</button>'
        // +'<img class="okimg" src="http://img.qxgs.cc/tiantianlaishouzu/img/task/ywc.png" alt="">'
        "</div>";
    }
    ele.list_room.innerHTML = html;
    // !渲染进度条
    let jinduAll = document.querySelectorAll("#jindu");
    jinduAll.forEach((item) => {
      if (parseInt(item.dataset.left) >= parseInt(item.dataset.right)) {
        // console.log(1);
        item.style.width = "calc(100% - 4px)";
      } else {
        let wi = (item.dataset.left / item.dataset.right) * 100;
        item.style.width = wi + "%";
      }
    });
    // !绑定点击领取事件
    let btn_ling_sAll = document.querySelectorAll("#btn_ling_s");
    btn_ling_sAll.forEach((item) => {
      item.onclick = () => {
        lingqu(item.dataset.id);
      };
    });
    // !点击招财猫
    ele.zhaocaijinbao.onclick = () => {
      if (!zhao) {
        return openTips("入住世纪城或铭门首付开启活动");
      }
      if (zhao && zhao.h_id && zhao.h_id == 1) {
        openTips("入住世纪城或铭门首付开启活动");
        return;
      }
      location.href = `../page/wealth.html?${zhao.h_id}`;
    };
    // !点击前往任务
    let qianwang_renwuAll = document.querySelectorAll("#qianwang_renwu");
    qianwang_renwuAll.forEach((item) => {
      item.onclick = () => {
        if (item.dataset.id == 1) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 2) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 3) {
          location.href = "../page/energy_Fang.html";
        } else if (item.dataset.id == 4) {
          location.href = "../page/directEmploy.html";
        } else if (item.dataset.id == 5) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 6) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 7) {
          location.href = "../page/home.html";
        } else if (item.dataset.id == 8) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 9) {
          location.href = "../page/search.html";
        } else if (item.dataset.id == 10) {
          location.href = "../page/leyuan.html";
        } else if (item.dataset.id == 11) {
          location.href = "../page/mine3.html";
        }
      };
    });
  }

  // !每周任务----------------------------------------------------------------------------------
  // function drawListWeek(data) {
  // 	ele.num_jin.innerHTML = data.list[0].money;
  // 	// ele.yaoqing1.innerHTML = '邀请满'+data.list[0].num+'位好友('+data.detail.has_num+'/'+data.list[0].num+')'
  // 	ele.yaoqing2.innerHTML = '满足条件的好友('+data.detail.has_num+'/'+data.list[0].num+')'
  // 	// ele.yaoqing11.innerHTML = data.detail.has_num+'/'+data.list[0].num
  // 	ele.yaoqing22.innerHTML = data.detail.has_num+'/'+data.list[0].num
  // 	// console.log('每周任务',obj);
  // }

  function lingqu(id) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.LINGQU_TASK,
      method: "post",
      header: {
        Authorization: token,
      },
      data: {
        id: id,
      },
      success: (res) => {
        openTips(res.msg);
        // 刷新列表
        taskList(types);
      },
    });
  }

  let weekid = "";
  let lingquyaoqing = "";
  taskWeekIndex(1);
  // 赵强强  每周任务
  function taskWeekIndex(page) {
    ele.more.innerText = "加载中...";
    let token = getCookie("token");
    ajax({
      url: API_PATH.TASK_WEEK_INDEX,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        page: page,
      },
      success: (res) => {
        if (res.code == 1) {
          drawWeekList(res.data);
          let detail = res.data.friend_list.data;
          if (detail.length === 0) {
            page = 0;
            ele.more.style.display = "none";
            ele.empty.style.display = "block";
          } else {
            drawDetail(detail);
            page++;
            if (page > res.data.friend_list.last_page) {
              ele.more.innerText = "没有更多了";
              ele.more.onclick = null;
            } else {
              ele.more.innerText = "加载更多";
              ele.more.onclick = () => taskWeekIndex(page);
            }
          }
        }
      },
    });
  }

  function drawDetail(data) {
    if (data.length === 0) {
      page = 0;
      ele.more.style.display = "none";
      ele.empty.style.display = "block";
    } else {
      let str = "";
      for (let i = 0; i < data.length; i++) {
        let sign =
          data[i].house == null
            ? "拥有房产"
            : data[i].house.type == 1
            ? "房产证"
            : "居住证";
        let time = "";
        // let  : '已拥有' + data[i].has_time + '小时'
        if (data[i].house_name == "") {
          time = "未拥有";
        } else {
          // let statTime = setInterval(() => {
          //   if (data.over_tim * 1000 <= +new Date()) {
          //     clearInterval(statTime);
          //     item.innerHTML = `0小时`;
          //     return;
          //   }
          //   time = '已拥有' + getCountMiao(data[i].has_time);
          // }, 1000);
          time = data[i].fcz_info.info.name;
        }
        let cls = data[i].house == null ? "green" : "";
        let head_pic = "";
        let nick_name = "";
        if (data[i].detail == null) {
          head_pic = "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png";
          nick_name = "对方暂未设置";
        } else {
          nick_name = data[i].detail.nick_name;
          if (data[i].detail.head_pic != null) {
            head_pic = IMG_DOMAIN + data[i].detail.head_pic;
          } else {
            if (data[i].detail.sex == 1) {
              head_pic = "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png";
            } else {
              head_pic = "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png";
            }
          }
        }

        str += `<div class="weekList">
							<div class="weekLeft">
								<img src="${head_pic}" alt="" />
								<div class="weekIn">
									<p>${nick_name}</p>
									<span>${data[i].mobile}</span>
								</div>
							</div>
							<div class="weekRight">
								<p>${sign}</p>
								<span class="${cls}">${time}</span>
							</div>
						</div>`;
      }
      ele.weekList.innerHTML += str;
    }
  }

  function drawWeekList(data) {
    weekid = data.list[0].id;
    let statTime = setInterval(() => {
      if (data.over_tim * 1000 <= +new Date()) {
        clearInterval(statTime);
        item.innerHTML = `0天00:00:00`;
        return;
      }
      ele.activeTime.innerHTML =
        "活动剩余时间：" + getCountTimeDay(data.over_time);
    }, 1000);
    lingquyaoqing = data.list[0].is_check;
    if (lingquyaoqing == 0) {
      ele.yq_lingqu.onclick = () => {
        taskGetWeekReward(weekid);
      };
    } else {
      ele.yq_lingqu.innerHTML = "已领取";
      ele.yq_lingqu.onclick = null;
      ele.yq_lingqu.style.filter = "grayscale(100%)";
    }
    ele.gian1.innerHTML =
      data.list[0].describe + "可获得" + data.list[0].money + "金币";
    ele.num_jin.innerHTML = data.list[0].money;
    ele.yaoqing2.innerHTML =
      "满足条件的好友(" + data.list[0].has_num + "/" + data.list[0].num + ")";
    ele.yaoqing22.innerHTML = data.list[0].has_num + "/" + data.list[0].num;
    if (parseInt(data.list[0].has_num) > parseInt(data.list[0].num)) {
      ele.yaoqing2_jdt.style.width = "calc(100% - 4px)";
    }
    ele.yaoqing2_jdt.style.width =
      (data.list[0].has_num / data.list[0].num) * 100 + "px";
    // console.log(ele.yaoqing2_jdt.style.width);
  }

  // console.log();

  // 领取按钮 每周任务
  function taskGetWeekReward(id) {
    let token = getCookie("token");
    ajax({
      url: API_PATH.TASK_GET_WEEK_REWARD,
      method: "POST",
      header: {
        Authorization: token,
      },
      data: {
        id: id,
      },
      success: (res) => {
        if (res.code == 1) {
          openTips(res.msg);
          ele.yq_lingqu.innerHTML = "已领取";
          ele.yq_lingqu.onclick = null;
          ele.yq_lingqu.style.filter = "grayscale(100%)";
          taskWeekIndex(1);
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  // 赵强强 推广任务
  tgIndex();
  function tgIndex() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.TG_INDEX,
      method: "GET",
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.code == 1) {
          // openTips(res.msg);
          ele.yqxq1.innerHTML = "历史奖励" + res.data.has_num + "人";
          ele.leiji.innerHTML = res.data.all_money;

          ele.tg_remark1.innerHTML = res.data.list[0].describe;
          ele.tg_remark11.innerHTML =
            "已完成人数：" + res.data.list[0].has_num + "人";
          ele.tg_remark111.innerHTML = "￥" + parseInt(res.data.list[0].money);
          ele.tg_remark2.innerHTML = res.data.list[1].describe;
          ele.tg_remark22.innerHTML =
            "已完成人数：" + res.data.list[1].has_num + "人";
          ele.tg_remark222.innerHTML = "￥" + parseInt(res.data.list[1].money);
          // ele.tg_remark3.innerHTML = res.data.list[2].describe
          // ele.tg_remark33.innerHTML ='已完成人数：'+res.data.list[2].has_num+'人'
          // ele.tg_remark333.innerHTML = '￥' + parseInt(res.data.list[2].money)
          ele.wodemoney.innerHTML = res.data.detail.sy_num;
          ele.wuwei.innerHTML = res.data.detail.has_yq;

          for (let i = 0; i < yqxqs.length; i++) {
            yqxqs[i].setAttribute("data", res.data.list[i].id);
          }

          let detail = res.data.lq_list.data;
          if (detail.length === 0) {
            page = 0;
            ele.more1.style.display = "none";
            ele.empty1.style.display = "block";
          } else {
            lingquList(detail);
            page++;
            if (page > res.data.lq_list.last_page) {
              ele.more1.innerText = "没有更多了";
              ele.more1.onclick = null;
            } else {
              ele.more1.innerText = "加载更多";
              ele.more1.onclick = () => getDetail(page);
            }
          }
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  function lingquList(data) {
    if (data.length === 0) {
      page = 0;
      ele.more.style.display = "none";
      ele.empty.style.display = "block";
    } else {
      let str = "";
      for (let i = 0; i < data.length; i++) {
        let resume = data[i].remark;
        let sign = data[i].operation_type == 1 ? "+" : "-";
        str +=
          '<div class="navlist">' +
          "<p>" +
          data[i].created_at +
          "</p>" +
          "<span>" +
          data[i].money +
          "</span>" +
          "</div>";
      }
      ele.navcont.innerHTML += str;
    }
  }

  ele.shouyibtn.onclick = () => {
    getSyMoney();
  };

  // 领取按钮 推广任务
  function getSyMoney() {
    let token = getCookie("token");
    ajax({
      url: API_PATH.GET_SY_MONEY,
      method: "get",
      header: {
        Authorization: token,
      },
      success: (res) => {
        if (res.code == 1) {
          openTips(res.msg);
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  let page_tg = 1;
  let xiangqing_id = "";
  let yqxqs = $(".yqxq");
  for (let i = 0; i < yqxqs.length; i++) {
    yqxqs[i].onclick = () => {
      if (i == 2) {
        ele.is_direct.innerHTML = "间推好友";
      } else {
        ele.is_direct.innerHTML = "直推好友";
      }
      openMdl(ele.modal_record2);
      let id = yqxqs[i].getAttribute("data");
      xiangqing_id = yqxqs[i].getAttribute("data");
      ele.navcont2.innerHTML = "";
      taskTgDetail(id, page_tg);
      // console.log(id);
    };
  }

  ele.yqxq1.onclick = () => {
    ele.is_direct.innerHTML = "直推好友";
    openMdl(ele.modal_record2);
    ele.navcont2.innerHTML = "";
    taskTgDetail(14, page_tg);
    // console.log(id);
  };

  function taskTgDetail(id, page, code) {
    // let data = ''
    if (!code) {
      code = "";
    }
    let token = getCookie("token");
    ajax({
      url: API_PATH.TASK_TG_DETAIL,
      method: "GET",
      header: {
        Authorization: token,
      },
      data: {
        id: id,
        page: page,
        code: code,
      },
      success: (res) => {
        if (res.code == 1) {
          // openTips(res.msg);
          let detail = res.data.list.data;
          if (detail.length === 0) {
            page = 0;
            ele.more2.style.display = "none";
            ele.empty2.style.display = "flex";
          } else {
            ele.more2.style.display = "block";
            ele.empty2.style.display = "none";
            drawTaskTgDetail(detail);
            page++;
            if (page > res.data.list.last_page) {
              ele.more2.innerText = "没有更多了";
              ele.more2.onclick = null;
            } else {
              ele.more2.innerText = "加载更多";
              ele.more2.onclick = () => taskTgDetail(id, page);
            }
          }
        } else openTips(res.msg || "未知错误");
      },
    });
  }

  function drawTaskTgDetail(data) {
    if (data.length === 0) {
      page_tg = 0;
      ele.more.style.display = "none";
      ele.empty.style.display = "flex";
    } else {
      let str = "";
      for (let i = 0; i < data.length; i++) {
        let resume = data[i].remark;
        let sign = data[i].operation_type == 1 ? "+" : "-";
        let head_pic = "";
        // let is_use = data[i].from_agent.is_use == 0 ? '' : '<span class="fontgreen">已领取</span>'
        // console.log(data[i].from_agent.detail.head_pic);
        let is_use =
          data[i].is_use == 0 ? "" : '<span class="fontgreen">已领取</span>';
        if (data[i].from_agent.detail.head_pic == null) {
          head_pic =
            data[i].from_agent.detail.sex == 1
              ? "../img/my/tx1.png"
              : "../img/my/tx2.png";
        } else {
          head_pic = IMG_DOMAIN + data[i].from_agent.detail.head_pic;
        }
        let name = data[i].from_agent.detail.nick_name;
        let invite_code = data[i].from_agent.invite_code;
        let fcz = data[i].house_name == null ? "无" : data[i].house_name;

        str += `<div class="navcont2in">
							<div class="navlist2">
								<p>${data[i].rank}</p>
								<img src="${head_pic}" alt="">
								<div class="">
									<span>${name}</span>
									<span>游戏ID：${invite_code}</span>
									${is_use}
								</div>
							</div>
							<div class="navRight">${fcz}</div>
						</div>`;
      }
      ele.navcont2.innerHTML += str;
    }
  }

  ele.search.onclick = () => {
    let code = ele.iptvalue.value;
    ele.navcont2.innerHTML = "";
    taskTgDetail(xiangqing_id, page_tg, code);
  };
})();
